package plenprojects.guiclient.panels;

import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Arrays;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileFilter;
import plenprojects.guiclient.frames.MainFrame;

public class RegisterPanel extends javax.swing.JPanel {
    
    private final MainFrame mainFrame;
    private final String id;
    
    public RegisterPanel(MainFrame mainFrame, String id) {
        
        this.id = id;
        this.mainFrame = mainFrame;
        this.initComponents();
    }
    
    public String getId() {
        
        return id;
    }
    
    public void clearAll() {
        
        UsernameInput.setText("");
        PasswordInput.setText("");
        RepeatPassword.setText("");
        DescriptionTextArea.setText("");
        FilenameLabel.setText("Select an image for your profile avatar.");
        ImagePreview.setIcon(null);
        ImagePreview.setText("Preview");
        ErrorLabel.setText("");
        DescriptionTextArea.setText("Your description");
        
    }
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        UsernameInput = new javax.swing.JTextField();
        PasswordInput = new javax.swing.JPasswordField();
        RepeatPassword = new javax.swing.JPasswordField();
        jScrollPane1 = new javax.swing.JScrollPane();
        DescriptionTextArea = new javax.swing.JTextArea();
        BrowseFilesButton = new javax.swing.JButton();
        FilenameLabel = new javax.swing.JLabel();
        SubmitButton = new javax.swing.JButton();
        UsernameLabel = new javax.swing.JLabel();
        PasswordLabel = new javax.swing.JLabel();
        RepeatPasswordLabel = new javax.swing.JLabel();
        BackButton = new javax.swing.JButton();
        ErrorLabel = new javax.swing.JLabel();
        ImagePreview = new javax.swing.JLabel();
        ClearAllButton = new javax.swing.JButton();

        DescriptionTextArea.setColumns(20);
        DescriptionTextArea.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        DescriptionTextArea.setRows(5);
        DescriptionTextArea.setText("Your description");
        jScrollPane1.setViewportView(DescriptionTextArea);

        BrowseFilesButton.setText("Select a file");
        BrowseFilesButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BrowseFilesButtonActionPerformed(evt);
            }
        });

        FilenameLabel.setText("Select an image for your profile avatar.");

        SubmitButton.setText("Register");
        SubmitButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SubmitButtonActionPerformed(evt);
            }
        });

        UsernameLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        UsernameLabel.setText("Username: ");

        PasswordLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        PasswordLabel.setText("Password: ");

        RepeatPasswordLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        RepeatPasswordLabel.setText("Repeat password: ");

        BackButton.setText("Back");
        BackButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BackButtonActionPerformed(evt);
            }
        });

        ErrorLabel.setForeground(new java.awt.Color(255, 0, 0));
        ErrorLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        ErrorLabel.setVerticalAlignment(javax.swing.SwingConstants.TOP);

        ImagePreview.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        ImagePreview.setText("Preview");
        ImagePreview.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        ClearAllButton.setText("Clear all");
        ClearAllButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ClearAllButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(ErrorLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(RepeatPasswordLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(PasswordLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(UsernameLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(PasswordInput, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
                            .addComponent(UsernameInput, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(RepeatPassword)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(BackButton)
                        .addGap(18, 18, 18)
                        .addComponent(ClearAllButton)))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(BrowseFilesButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(FilenameLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jScrollPane1)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(SubmitButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(ImagePreview, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(BackButton)
                            .addComponent(ClearAllButton))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(UsernameInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(UsernameLabel))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(PasswordInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(PasswordLabel))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(RepeatPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(RepeatPasswordLabel)))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(BrowseFilesButton)
                            .addComponent(FilenameLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(ImagePreview, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(SubmitButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(ErrorLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 4, Short.MAX_VALUE)))
                .addContainerGap())
        );
    }// </editor-fold>                        

    private void BackButtonActionPerformed(java.awt.event.ActionEvent evt) {                                           
        
        //TODO
        
    }                                          

    private void ClearAllButtonActionPerformed(java.awt.event.ActionEvent evt) {                                               
        
        //TODO
        
    }                                              

    private void BrowseFilesButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                  
        
        //TODO
        
    }                                                 

    private void SubmitButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
        
        //TODO
        
    }                                            

    // Variables declaration - do not modify                     
    private javax.swing.JButton BackButton;
    private javax.swing.JButton BrowseFilesButton;
    private javax.swing.JButton ClearAllButton;
    private javax.swing.JTextArea DescriptionTextArea;
    private javax.swing.JLabel ErrorLabel;
    private javax.swing.JLabel FilenameLabel;
    private javax.swing.JLabel ImagePreview;
    private javax.swing.JPasswordField PasswordInput;
    private javax.swing.JLabel PasswordLabel;
    private javax.swing.JPasswordField RepeatPassword;
    private javax.swing.JLabel RepeatPasswordLabel;
    private javax.swing.JButton SubmitButton;
    private javax.swing.JTextField UsernameInput;
    private javax.swing.JLabel UsernameLabel;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration                   
}
